#coding=utf-8
import glob
import jieba
import re
import json
from common.attr_v2 import AttrV2
from database.db_handler import MysqlHander
from common.entity_data import EntityData

'''
指數转set
'''

class ZhishuSet:
    def __init__(self):
        self.db = MysqlHander("config.ini")
        self.entity = EntityData()
    
    def process(self):
        query = "select Fattribute_name,Fmatch_text from attribute_data where Frelation_id=2001;"
        print(query)
        datas = self.db.query_sql(query)
        for data in datas:
            name = data[0] + "成分股"
            print(name)
            if data[1] == "":
                continue
            sets = ""
            json_data = json.loads(data[1])
            for k in json_data["nodes"]:
                sets += k["name"].replace(" ","") +  "|"
            #print(name + ":" + sets)
            #self.entity.add_entity_data(name, "", 100, 1000001, "A股", "", sets)
            self.entity.update_entity_data(name, "", 100, 1000001, "A股", "", sets)

def zhishu_set_api():
    zhishu = ZhishuSet()
    zhishu.process()

if __name__ == '__main__':
    zhishu_set_api()
